package com.yang.yangLoad;

import com.yang.Main;
import org.bukkit.configuration.file.YamlConfiguration;

import javax.annotation.Resource;
import java.io.File;

/*加载自定义的yml*/
public class DataLoader {

    private static Main main;

    public DataLoader(Main main) {
        this.main = main;
    }


    private static YamlConfiguration data;

    public static void loadData(){
        File file = new File(main.getDataFolder(),"data.yml");
        if (!file.exists()){
            main.getLogger().info("data.yml 文件不存在，已创建新文件");
            main.saveResource("data.yml",false);
        }
        data = YamlConfiguration.loadConfiguration(file);
        if (data == null) {
            main.getLogger().warning("无法加载 data.yml 文件！");
            return;
        }
        main.getLogger().info("data.yml 文件成功加载");
    }

    public static YamlConfiguration getData() {
        return data;
    }

    /*重载*/
    public static void reloadConfig(){
        main.reloadConfig();
        loadData();
    }

}
